let oldArrayPrototype = Array.prototype;
export let arrayMethods = Object.create(Array.prototype); //复制原型对象
let methods = ['push','pop','shift','unshift','sort','splice','reverse']

methods.forEach((method)=>{
    arrayMethods[method] = function(...args){ //重写原型上的方法
        let result = oldArrayPrototype[method].call(this,...args)  //AOP切片，对数组的7个可改变原数组的方法进行拦截，并保证原方法可用
        let inserted;  //数组
        switch (method) {
            case 'push':   //数组增加数据
            case 'unshift':
                inserted = args;
                break;
            case 'splice':  
                inserted = args.slice(2)  //splice(index,howmany,xxx)      
                break;
            default:
                break;
        }
        if(inserted) this.__ob__.observeArray(inserted)
        return result; 
    }
})